package com.pro.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:LoginUser
 * Package:com.pro.pojo
 * Description:
 *
 * @Date:2022/1/8 20:56
 * @Author: XJR
 */
public class LoginUser implements UserDetails {

    private JsUser user;

    private List<String> permissions;

    public LoginUser() {
        super();
    }

    public LoginUser(JsUser user) {
        this.user = user;
    }

    public LoginUser(JsUser user, List<String> permissions) {
        this.user = user;
        this.permissions = permissions;
    }

    public JsUser getUser() {
        return user;
    }

    public void setUser(JsUser user) {
        this.user = user;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }
    @JSONField(serialize = false)
    private List<SimpleGrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        authorities = permissions.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
        return authorities;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
